//
//  ViewController.m
//  20-XMLCartoonHomeWork
//
//  Created by 曹曹 on 16/8/11.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ViewController.h"
#import "XMLReader.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self handleData];
}

- (void)handleData {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Cartoon" ofType:@"xml"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSError *error = nil;
    NSDictionary *dictionary = [XMLReader dictionaryForXMLData:data error:&error];
    NSLog(@"%@", dictionary);
    NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = pathArray.firstObject;
    NSLog(@"%@", documentPath);
    NSString *dictionaryPath = [documentPath stringByAppendingPathComponent:@"cartoon.json"];
    [dictionary writeToFile:dictionaryPath atomically:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
